package com.ydd.controller.admin;

import com.ydd.dto.YddAdvposQueryDTO;
import com.ydd.dto.YddTagQueryDTO;
import com.ydd.entity.YddAdvpos;
import com.ydd.entity.YddTag;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.YddAdvposService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ydd_advpos")
@Slf4j
@Api(tags = "管理端-广告位管理相关接口")
public class YddAdvposController {
    @Autowired
    private YddAdvposService yddAdvposService;

    /**
     * 广告位分页
     * @param yddAdvposQueryDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("广告位分页")
    public Result<PageResult> page(YddAdvposQueryDTO yddAdvposQueryDTO){
        log.info("广告位分页:{}", yddAdvposQueryDTO);
        PageResult pageResult = yddAdvposService.page(yddAdvposQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 广告位详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("广告位详情")
    public Result<YddAdvpos> getById(Integer id){
        log.info("广告位详情:{}", id);
        YddAdvpos yddAdvpos = yddAdvposService.getById(id);
        return Result.success(yddAdvpos);
    }

    /**
     * 广告位添加
     * @param yddAdvpos
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("广告位添加")
    public Result add(@RequestBody YddAdvpos yddAdvpos){
        log.info("广告位添加");
        yddAdvposService.add(yddAdvpos);
        return Result.success();
    }

    /**
     * 广告位-全部
     * @param
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("广告位-全部")
    public Result<List<YddAdvpos>> all(){
        log.info("广告位-全部:{}");
        List<YddAdvpos> yddAdvposList= yddAdvposService.all();
        return Result.success(yddAdvposList);
    }

    /**
     * 广告位修改
     * @param yddAdvpos
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("广告位修改")
    public Result update(@RequestBody YddAdvpos yddAdvpos){
        log.info("广告位修改:{}",yddAdvpos);
        yddAdvposService.update(yddAdvpos);
        return Result.success();
    }

    /**
     * 广告位删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("广告位删除")
    public Result delete(Integer id){
        log.info("广告位删除:{}", id);
        yddAdvposService.delete(id);
        return Result.success();
    }
}
